#pragma once

#include <list>
#include <algorithm>

template <class T>
class TMgr
{
public:
	TMgr()
	{

	}

	~TMgr()
	{
		destory();
	}

public:
	T *create()
	{
		T *t = new T;

		_ts.push_back(t);

		return t;
	}

	void destory(T *t)
	{
		delete t;
		_ts.remove(t);
	}

	void destory()
	{
		while (_ts.size() != 0)
		{
			destory(_ts.front());
		}
	}

	T *get(size_t index)
	{
		std::list<T *>::iterator it = _ts.begin();
		std::advance(it, index);

		if (it == _ts.end())
		{
			return NULL;
		}

		return *it;
	}

	T *get(T *t)
	{
		std::list<T *>::iterator it = std::find(_ts.begin(), _ts.end(), bus);

		if (it == _ts.end())
		{
			return NULL;
		}

		return *it;
	}

private:
	std::list<T *>	_ts;
};